package com.sgq.vue.utils.system;

import com.sgq.vue.entity.system.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author: 83778
 * @date: 2024-01-10 15:55
 * @desc:
 */
public class MySecurityContextHolder {

    private static User getSysUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User user = (User)authentication.getPrincipal();
        return user;
    }

    public static Long getSysUserId(){
        User user = getSysUser();
        return user.getId();
    }

    public static String getSysUsername(){
        User user = getSysUser();
        return user.getUsername();
    }
}
